<!--DOI TRANG THAI-->
<?php
if (isset($_GET['change']))
{
    $lamnhanhid = $_GET ['lamnhanhid'];
    //echo $lamnhanhid;
    $result=mysql_query("select * from lamnhanh where lamnhanhid=$lamnhanhid");
    while ($row = mysql_fetch_array($result))
        {
            if ("$row[tinhtrang]" == 1) $result2 = mysql_query("update lamnhanh set tinhtrang = 0 where lamnhanhid=$lamnhanhid;");
            else $result2 = mysql_query("update lamnhanh set tinhtrang = 1 where lamnhanhid=$lamnhanhid;");
            if ($result2)
                    print '<h2>Thành công !</h2>';
        }
}
?>

<!--XOA LAM NHANH-->
<?php
if (isset($_GET['remove']))
{
    $lamnhanhid = $_GET ['lamnhanhid'];
    $result = mysql_query("DELETE FROM lamnhanh where lamnhanhid = $lamnhanhid; ");
    if ($result)
        print '<h2>Xóa thành công !</h2>';
}
?>

<!--FORM THEM LAM NHANH-->
<form action="index.php?sanxuat&module=lamnhanh" method="post" enctype="multipart/form-data">
<fieldset>
<legend><h1>Thêm gói thời gian</h1></legend>
<table width="408" border="0">
  <tr>
    <td width="300">Thời gian </td>
    <td width="318"><label>
      <input type="text" name="thoigianlam" id="textfield" /> ngày
    </label></td>
  </tr>
  <tr>
    <td>Thêm tiền</td>
    <td><input type="text" name="themtien" value="0" onfocus="this.value=''" onKeyUp="executeComma(event);" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input class="button" type="submit" name="submit" value="Thêm" /></td>
  </tr>
</table>
</fieldset>
</form>

<!--PHP THEM LAM NHANH-->
<?php
if (isset($_POST['submit']))
{
    //print_r ($_POST);
    $thoigianlam      =   $_POST['thoigianlam'];
    $tinhtrang      =   1;
    $themtien        =   $_POST['themtien'];
    $mysql = "insert into lamnhanh (thoigianlam, tinhtrang, themtien) values ('$thoigianlam','$tinhtrang', '$themtien')";
    $result = mysql_query($mysql);
    if ($result)
        print '<h2>Thành công !</h2>';
    
    
}
?>

<!--HIEN THI CAC GOI KHUYEN MAI-->
<fieldset>
<legend><h1>Các gói đang áp dụng :</h1></legend>
<table width="695" border="0">
    <tr>
        <td width="50"><b>ID</b></td>
        <td width="300"><b>Gói thời gian</b></td>
        <td width="200"><b>Tình trạng</td>
        <td width="200"><b>Phụ thu</b></td>
        <td width="400"><b>Đổi tình trạng</b></td>
    </tr>

    <?php
        $lamnhanh = mysql_query("select * from `lamnhanh`");
        while ($row = mysql_fetch_array($lamnhanh))
        {
    ?>
    <tr>
        <td><?php print "$row[lamnhanhid]"; ?> </td>
        <td><?php print "$row[thoigianlam]"; ?> ngày</td>
        <td><?php if ("$row[tinhtrang]" == 1) print "Cho phép";
                    else print "Không cho phép"; ?></td>
        <td><?php print "$row[themtien]";?> </td>
        <td>
        <a href="index.php?sanxuat&module=lamnhanh&lamnhanhid=<?php print "$row[lamnhanhid]"; ?>&change">Đổi trạng thái</a>
        <!--<a href="index.php?sanxuat&module=lamnhanh&lamnhanhid=<?php print "$row[lamnhanhid]"; ?>&remove" onclick="return confirm('Muốn xóa thật ko?')" >/ Xóa</a>-->
        </td>
    </tr>
    <?php 
        }
    ?>
</table>
</fieldset>
